<template>
	<view class="paper-content">
		<!-- 操作菜单 -->
		<paper-left-popup :shows="show" @getshow="getshow"></paper-left-popup>
		<!-- 小纸条列表 -->
		<block v-for="(item, index) in list" :key="index"><paper-list :item="item" :index="index"></paper-list></block>
		<load-more :loadtext="loadtext"></load-more>
	</view>
</template>

<script>
import paperList from '../../components/paper/paper-list.vue';
import loadMore from '../../components/common/load-more.vue';
import paperLeftPopup from '../../components/paper/paper-left-popup.vue';
export default {
	data() {
		return {
			show: false,
			loadtext: '上拉加载更多',
			list: [
				{
					userpic: '../../static/demo/userpic/12.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息我是信息我是信息我是信息我是信息我是信息我是信息我是信息我是信息',
					noreadnum: 2
				},
				{
					userpic: '../../static/demo/userpic/10.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 4
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 0
				},
				{
					userpic: '../../static/demo/userpic/12.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 6
				},
				{
					userpic: '../../static/demo/userpic/13.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 2
				},
				{
					userpic: '../../static/demo/userpic/13.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 2
				},
				{
					userpic: '../../static/demo/userpic/13.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 2
				},
				{
					userpic: '../../static/demo/userpic/13.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 2
				},
				{
					userpic: '../../static/demo/userpic/13.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 2
				}
			]
		};
	},
	// 下拉刷新
	onPullDownRefresh() {
		this.getdata();
	},
	// 上拉加载更多
	onReachBottom() {
		this.loadmore();
	},
	// 监听导航按钮点击事件
	onNavigationBarButtonTap(ev) {
		switch(ev.index){
			case 0:
			console.log('ekal')
				uni.navigateTo({
					url: '../user-list/user-list',
					animationType: 'slide-in-top'
				})
				break;
			case 1:
				if(this.show){
					this.show = !this.show
					return;
				}
				this.showpopup()
				break;
		}
	},
	methods: {
		getdata() {
			// 服务器获取数据
			let arr = [
				{
					userpic: '../../static/demo/userpic/12.jpg',
					username: '昵ewe称',
					time: '10:32',
					data: '我是信息我是信息我是信息我是信息我是信息我是信息我是信息我是信息我是信息',
					noreadnum: 2
				},
				{
					userpic: '../../static/demo/userpic/10.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息我是信息',
					noreadnum: 4
				},
				{
					userpic: '../../static/demo/userpic/11.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 5
				},
				{
					userpic: '../../static/demo/userpic/12.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 6
				},
				{
					userpic: '../../static/demo/userpic/13.jpg',
					username: '昵称',
					time: '10:32',
					data: '我是信息',
					noreadnum: 2
				}
			];
			setTimeout(() => {
				this.list = arr;
				uni.stopPullDownRefresh();
			}, 2000);
		},
		loadmore() {
			if (this.loadtext != '上拉加载更多') {
				return;
			}
			this.loadtext = '加载中...';
			uni.showLoading({
				title: '加载中...',
				mask: true,
				success: () => {
					let obj = {
						userpic: '../../static/demo/userpic/13.jpg',
						username: '昵称',
						time: '10:32',
						data: '我是信息',
						noreadnum: 2
					};
					setTimeout(() => {
						this.list.push(obj);
						uni.hideLoading();
						this.loadtext = '上拉加载更多';
					}, 1000);
				}
			});
		},
		showpopup() {
			this.show = true
		},
		getshow(show) {
			this.show = show
		}
	},
	components: {
		paperList,
		loadMore,
		paperLeftPopup
	}
};
</script>

<style scoped lang="scss">
.paper-content {
	width: 100%;
	padding: 0 20upx;
	box-sizing: border-box;
}
</style>
